package com.study.examples.controller;

import com.study.examples.config.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: RedisController
 * @Description:
 * @author: limingxing
 * @Date: 2020-01-15 16:28
 */
@RestController
public class RedisController {

    @Autowired
    private RedisUtils redisUtils;

    @PostMapping("set")
    public Object set(String key,String value){
        return redisUtils.set(key,value);
    }

    @PostMapping("get")
    public Object get(String key){
        return redisUtils.get(key);
    }

    @PostMapping("/getLock")
    public Object getLock(String key,String value){
        Boolean is = redisUtils.getLock(key,value,5000);
        try{
            Thread.sleep(1500L);
        }catch (Exception e){}
        if(is){
            redisUtils.unlock(key,value);
        }
        return is;
    }



}
